package dk.dashboardFP.utils.keyListener {

	/**
	 * @author josef
	 */
	public class KeyListenerKey {
		private var _uintKeyCode : uint;
		private var _a_fCallbacks : Array;
		private var _bOnlyDispatchOneDown : Boolean;

		public function KeyListenerKey(uintKeyCode : uint, bOnlyDispatchOneDown : Boolean = true) {
			
			_bOnlyDispatchOneDown = bOnlyDispatchOneDown;
			_uintKeyCode = uintKeyCode;
			
			setup();
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// execute
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

		public function execute() : void {
			for each (var fCallback : Function in _a_fCallbacks) {
				fCallback();
			}
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// setup
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

		private function setup() : void {
			_a_fCallbacks = [];
		}

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
		// callbacks
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

		public function addCallBack(fCallback : Function) : void {
			_a_fCallbacks.push(fCallback);
		}

		public function removeCallback(fCallback : Function) : void {
			if (fCallback != null) {
				if (_a_fCallbacks.indexOf(fCallback) != -1) {
					_a_fCallbacks.splice(_a_fCallbacks.indexOf(fCallback), 1);
				}
			} else {
				while(_a_fCallbacks.length != 0) {
					_a_fCallbacks.splice(0, 1);
				}
			}
		}

		public function get bOnlyDispatchOneDown() : Boolean {
			return _bOnlyDispatchOneDown;
		}
	}
}
